<?
include_once('../common/autoload.php');
$did=$_REQUEST["did"];
$tplid=$_REQUEST["tplid"];
$tpl=Tpl::getLink();
if(($res=$tpl->apply($did,$tplid))===true){
	$sel="select dname from pft_member where id=".$did." limit 1";
	$GLOBALS['le']->query($sel);
	$GLOBALS['le']->fetch_assoc();
	$dname=$GLOBALS['le']->f("dname");
	if($tplid){
		$sel="select title from uu_fx_pri_tpl where id=".$tplid." limit 1";
		$GLOBALS['le']->query($sel);
		$GLOBALS['le']->fetch_assoc();
		$title=$GLOBALS['le']->f("title");
	}
	$ins="insert pft_d_operation_rec set fid=".$_SESSION['memberID'].",sid=".$_SESSION['sid'].",daction='".($tplid?"给".$dname."套用模板".$title:"解除".$dname."的模板套用")."',rectime=now()";
	$GLOBALS['le']->query($ins);
	if($tplid){
		echo "套用成功";
	}
	else{
		echo "已解除套用";
	}
}
else{
	echo $res;
}
?>